package validator;

import model.type.ContactType;
import model.type.SubjectType;

public class ContactValidator {
	private Integer id = null, subject = null, subjectType = null, order = null, type = null;
	private String text = null, note = null;
	
	public ContactValidator(String id, String subject, String subjectType, 
			String type, String text, String note, String order){
		try{
			this.id = Integer.parseInt(id);
		} catch(NullPointerException | NumberFormatException e){}
		try{
			this.subject = Integer.parseInt(subject);
		} catch(NullPointerException | NumberFormatException e){}
		try{
			this.subjectType = Integer.parseInt(subjectType);
		} catch(NullPointerException | NumberFormatException e){}
		try{
			this.order = Integer.parseInt(order);
		} catch(NullPointerException | NumberFormatException e){}
		try{
			this.type = Integer.parseInt(type);
		} catch(NullPointerException | NumberFormatException e){}
		if(text != null) this.text = !text.isEmpty() ? text: null;
		if(note != null) this.note = !note.isEmpty() ? note: null;				
	}
	
	public boolean isValid(){
		return id != null && subject != null && subjectType != null 
				&& order != null && type != null && text != null 
				&& (subjectType == SubjectType.ENTERPRISE || subjectType == SubjectType.PERSON)
				&& (type == ContactType.MAIL || type == ContactType.PHONE);
	}

	public Integer getId() {
		return id;
	}

	public Integer getSubject() {
		return subject;
	}

	public Integer getSubjectType() {
		return subjectType;
	}

	public Integer getOrder() {
		return order;
	}

	public Integer getType() {
		return type;
	}

	public String getText() {
		return text;
	}

	public String getNote() {
		return note;
	}
	
	
}
